package com.atguigu.weixin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.atguigu.crud.service.WxgroupService;
import com.atguigu.weixin.user.model.WGroup;

/**
 * 微信分组接口
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/wgroup")
public class WGroupController {
	@Autowired
	private WxgroupService wxgroupService;

	@RequestMapping("/list")
	public String list(Model model) {
		model.addAttribute("datas",wxgroupService.queryAll());
		return "admin/wgroup/list";
	}
	
	@RequestMapping("/query/{openid}")
	public String list(@PathVariable String openid,Model model) {
		model.addAttribute("wg",wxgroupService.queryUserGroup(openid));
		return "admin/wgroup/query";
	}
	
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model) {
		model.addAttribute("wg", new WGroup());
		return "admin/wgroup/add";
	}
	
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public String add(WGroup wg) {
		wxgroupService.add(wg);
		return "redirect:/wgroup/list";
	}
}
